package com.lanou3g.code0426;

import jdk.internal.org.objectweb.asm.tree.analysis.Value;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * Created by dllo on 18/4/26.
 */
public class Test02 {
    public static void main(String[] args) {

        try {
            //整个项目中驱动只需要注册一次
            Class.forName("com.mysql.cj.jdbc.Driver");
            //每一次执行sql都固定写的代码
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/lan_ou?","root","123456");
            Statement statement = conn.createStatement();

            String sql = "INSERT INTO stu (sid,sname,gender,age)" + "VALUES('123456','张三','男',18)";
            int rows = statement.executeUpdate(sql);
            if (rows > 0){
                System.out.println("插入成功");
            }else {
                System.out.println("插入失败");
            }

            conn.close();
            statement.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
